package com.tina.tinasso.exception;

import com.tina.tinasso.util.ResultFormat;
import com.tina.tinasso.util.ResultUtil;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义处理异常
 *
 * @author Tina
 * @version 0.0.1
 * @date 2020/7/2 16:30
 **/
@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(Exception.class)
    public ResultFormat handleException(Exception e) {
        e.printStackTrace();
        if (e instanceof CustomException) {
            return ResultUtil.error(e.getMessage());
        } else {
            return ResultUtil.error("未知错误：" + e.getMessage());
        }
    }
}
